<!DOCTYPE html>
<html>
<head>
<title>Electromagnetic Induction Diagram</title>
</head>
<body>

<canvas id="physicsCanvas" width="600" height="400" style="border:1px solid #d3d3d3;"></canvas>

<script>
    const canvas = document.getElementById('physicsCanvas');
    const ctx = canvas.getContext('2d');

    // Style settings
    ctx.strokeStyle = 'black';
    ctx.fillStyle = 'black';
    ctx.lineWidth = 1.5;

    // Helper function to draw a V-shaped arrowhead on the current path
    function drawArrowHead(context, x, y, angle, headlen = 8) {
        context.moveTo(x, y);
        context.lineTo(x - headlen * Math.cos(angle - Math.PI / 6), y - headlen * Math.sin(angle - Math.PI / 6));
        context.moveTo(x, y);
        context.lineTo(x - headlen * Math.cos(angle + Math.PI / 6), y - headlen * Math.sin(angle + Math.PI / 6));
    }

    // Coordinates and dimensions
    const wireY = 80;
    const loopTopY = 140;
    const loopHeight = 120;
    const loopBottomY = loopTopY + loopHeight;
    const loopLeftX = 180;
    const loopWidth = 240;
    const loopRightX = loopLeftX + loopWidth;
    
    // 1. Draw the long straight wire with current arrow
    ctx.beginPath();
    ctx.moveTo(50, wireY);
    ctx.lineTo(550, wireY);
    drawArrowHead(ctx, 430, wireY, 0, 10); // angle 0 for right-pointing
    ctx.stroke();

    // 2. Draw current label 'I'
    ctx.font = 'italic 24px Times New Roman';
    ctx.textAlign = 'center';
    ctx.textBaseline = 'bottom';
    ctx.fillText('I', 415, wireY - 5);

    // 3. Draw the rectangular loop
    ctx.beginPath();
    ctx.rect(loopLeftX, loopTopY, loopWidth, loopHeight);
    ctx.stroke();
    
    // The image style for c and d includes extending lines.
    const extensionLength = 40;
    ctx.beginPath();
    ctx.moveTo(loopRightX, loopTopY);
    ctx.lineTo(loopRightX + extensionLength, loopTopY);
    ctx.moveTo(loopRightX, loopBottomY);
    ctx.lineTo(loopRightX + extensionLength, loopBottomY);
    ctx.stroke();

    // 4. Draw dimension lines for 'a' and 'b'
    const dimLineX = 120;
    ctx.lineWidth = 1;
    // Dimension 'a'
    ctx.beginPath();
    ctx.moveTo(dimLineX, wireY);
    ctx.lineTo(dimLineX, loopTopY);
    drawArrowHead(ctx, dimLineX, wireY, -Math.PI / 2); // Pointing up
    drawArrowHead(ctx, dimLineX, loopTopY, Math.PI / 2); // Pointing down
    // End caps for 'a'
    ctx.moveTo(dimLineX - 4, wireY);
    ctx.lineTo(dimLineX + 4, wireY);
    ctx.moveTo(dimLineX - 4, loopTopY);
    ctx.lineTo(dimLineX + 4, loopTopY);
    ctx.stroke();
    // Label 'a'
    ctx.font = 'italic 20px Times New Roman';
    ctx.textAlign = 'left';
    ctx.textBaseline = 'middle';
    ctx.fillText('a', dimLineX + 10, (wireY + loopTopY) / 2);

    // Dimension 'b'
    ctx.beginPath();
    ctx.moveTo(dimLineX, loopTopY);
    ctx.lineTo(dimLineX, loopBottomY);
    drawArrowHead(ctx, dimLineX, loopTopY, -Math.PI / 2); // Pointing up
    drawArrowHead(ctx, dimLineX, loopBottomY, Math.PI / 2); // Pointing down
    // End caps for 'b'
    ctx.moveTo(dimLineX - 4, loopTopY);
    ctx.lineTo(dimLineX + 4, loopTopY);
    ctx.moveTo(dimLineX - 4, loopBottomY);
    ctx.lineTo(dimLineX + 4, loopBottomY);
    ctx.stroke();
    // Label 'b'
    ctx.fillText('b', dimLineX + 10, (loopTopY + loopBottomY) / 2);
    
    ctx.lineWidth = 1.5; // Reset line width

    // 5. Labels 'c' and 'd'
    ctx.font = 'italic 20px Times New Roman';
    ctx.textAlign = 'center';
    ctx.textBaseline = 'bottom';
    ctx.fillText('c', loopRightX + extensionLength/2, loopTopY - 2);
    ctx.textBaseline = 'top';
    ctx.fillText('d', loopRightX + extensionLength/2, loopBottomY + 2);

    // 6. Velocity 'v'
    const v_arrow_y = (loopTopY + loopBottomY) / 2;
    ctx.beginPath();
    ctx.moveTo(loopRightX + extensionLength, v_arrow_y);
    ctx.lineTo(loopRightX + extensionLength + 50, v_arrow_y);
    drawArrowHead(ctx, loopRightX + extensionLength + 50, v_arrow_y, 0, 10);
    ctx.stroke();
    ctx.font = 'italic 22px Times New Roman';
    ctx.textAlign = 'left';
    ctx.textBaseline = 'middle';
    ctx.fillText('v', loopRightX + extensionLength + 55, v_arrow_y);

    // 7. Caption text
    ctx.font = '20px Simsun';
    ctx.textAlign = 'center';
    ctx.textBaseline = 'bottom';
    ctx.fillText('习题 9-4 图', canvas.width / 2, canvas.height - 20);

</script>

</body>
</html>